package com.ymatou.userservice.testcase;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.userservice.parameter.UnBindThirdPartyAccountDtoBean;
import com.ymatou.userservice.service.UnBindThirdPartyAccountDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.UserCallService;
import com.ymttest.database.sqlwapper.YmtUsersWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.ECode;
import com.ymttest.utils.constant.ThirdPartyType;

/**
*解绑第三方用户接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UnBindThirdPartyAccountDto{
	private static UnBindThirdPartyAccountDtoBean unbindthirdpartyaccountdtoBean;
	private static UnBindThirdPartyAccountDtoCall unbindthirdpartyaccountdtoCall;
	private static YmtUsersWapper userWapper;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("解绑第三方用户接口");
		userWapper = new YmtUsersWapper();
	}

	@Before
	public void caseUp() {
		unbindthirdpartyaccountdtoBean=new UnBindThirdPartyAccountDtoBean();
		unbindthirdpartyaccountdtoCall=new UnBindThirdPartyAccountDtoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(unbindthirdpartyaccountdtoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_UnBindThirdPartyAccountDto_001() {
		Logger.start(true,"用户绑定了微信账号，微博账号，阿里账号，依次解绑这些账号");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			List<Map> thirdParty = new ArrayList<Map>();
			
			Logger.comment("检查微信账号是否需要绑定手机号");
			String unionId = "unionId_"+TestDataManager.getRandomNum(10);
			UserCallService.checkThirdPartyNeedBindMobile(unionId, ThirdPartyType.WEIXIN, ECode.USER_YES);
			Logger.comment("传入手机号，使用微信账号创建洋码头账号");
			Map user = UserCallService.regByWeiXin(unionId, phone, true, "注册成功");
			
			Logger.comment("检查微博账号是否需要绑定手机号");
			String weiboUserId = "BindWeibo_"+TestDataManager.getRandomNum(10);
			UserCallService.checkThirdPartyNeedBindMobile(weiboUserId, ThirdPartyType.WEIBO, ECode.USER_YES);
			Logger.comment("传入和微信同样的手机号，使用微博账号登陆");
			UserCallService.regByWeibo(weiboUserId, phone, true, "登录成功");
			
			Logger.comment("检查阿里账号是否需要绑定手机号");
			String aliUserId = "ali_"+TestDataManager.getRandomNum(7);
			UserCallService.checkThirdPartyNeedBindMobile(aliUserId, ThirdPartyType.ALI, ECode.USER_YES);
			Logger.comment("传入和微信同样的手机号，使用阿里账号登陆");
			UserCallService.regByAli(aliUserId, phone, true, "登录成功");
			
			int userId = ((Double)user.get("userId")).intValue();
			Logger.comment("调用接口验证用户绑定了微博，微信，阿里账号");
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.ALI, aliUserId, true);
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIXIN, unionId, true);
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIBO, weiboUserId, true);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
			
			Logger.comment("解绑微信账号");
			Map result = UserCallService.unbindThirdParty(userId, unionId, ThirdPartyType.WEIXIN);
			Logger.verifyEquals(200d, result.get("ResponseCode"), "验证Code");
			Logger.verifyEquals(true, result.get("Success"), "验证是否成功");
			Logger.verifyEquals("ok", result.get("Result"), "验证Msg信息");
					
			Logger.comment("解绑微博账号");
			result = UserCallService.unbindThirdParty(userId, weiboUserId, ThirdPartyType.WEIBO);
			Logger.verifyEquals(200d, result.get("ResponseCode"), "验证Code");
			Logger.verifyEquals(true, result.get("Success"), "验证是否成功");
			Logger.verifyEquals("ok", result.get("Result"), "验证Msg信息");
			
			Logger.comment("解绑阿里账号");
			result = UserCallService.unbindThirdParty(userId, aliUserId, ThirdPartyType.ALI);
			Logger.verifyEquals(300d, result.get("ResponseCode"), "验证Code");
			Logger.verifyEquals(false, result.get("Success"), "验证是否成功");
			Logger.verifyEquals("请设置登录账号及密码", result.get("LastErrorMessage"), "验证Msg信息");
			
			Logger.comment("调用接口验证用户绑定了微博，微信，阿里账号");
			thirdParty.clear();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.ALI, aliUserId, true);
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIXIN, unionId, false);
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIBO, weiboUserId, false);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_UnBindThirdPartyAccountDto_002() {
		Logger.start(false, "用户只绑定了阿里账号，解绑阿里账号，提示不能解绑，需要设置登录信息");
		try {
			String aliUserId = "ali_"+TestDataManager.getRandomNum(7);
			Logger.comment("验证第三方账号需要绑定手机号");
			UserCallService.checkThirdPartyNeedBindMobile(aliUserId, ThirdPartyType.ALI, ECode.USER_YES);
			Logger.comment("传入手机号，创建阿里账号");
			String phone = TestDataManager.getPhoneNum();
			Map user = UserCallService.regByAli(aliUserId, phone, true, "注册成功");
			int userId = ((Double)user.get("userId")).intValue();
			
			Logger.comment("验证用户绑定了阿里账号");
			List<Map> thirdParty = new ArrayList<Map>();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.ALI, aliUserId, true);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
			
			Logger.comment("解绑阿里账号");
			Map result = UserCallService.unbindThirdParty(userId, aliUserId, ThirdPartyType.ALI);
			Logger.verifyEquals(300d, result.get("ResponseCode"), "验证Code");
			Logger.verifyEquals(false, result.get("Success"), "验证是否成功");
			Logger.verifyEquals("请设置登录账号及密码", result.get("LastErrorMessage"), "验证Msg信息");
			
			Logger.comment("设置登陆设置信息:邮箱，密码");
			String email = TestDataManager.getEmail();
			UserCallService.setLoginBills(userId, email);
			
			Logger.comment("再次解绑");
			result = UserCallService.unbindThirdParty(userId, aliUserId, ThirdPartyType.ALI);
			Logger.verifyEquals(200d, result.get("ResponseCode"), "验证Code");
			Logger.verifyEquals(true, result.get("Success"), "验证是否成功");
			Logger.verifyEquals("ok", result.get("Result"), "验证Msg信息");
			
			Logger.comment("验证用户绑定状态");
			thirdParty = new ArrayList<Map>();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.ALI, aliUserId, false);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
			
			Logger.comment("重复解绑");
			result = UserCallService.unbindThirdParty(userId, aliUserId, ThirdPartyType.ALI);
			Logger.verifyEquals(500d, result.get("ResponseCode"), "验证Code");
			Logger.verifyEquals(false, result.get("Success"), "验证是否成功");
			Logger.verifyEquals("此第三方账号已解绑", result.get("LastErrorMessage"), "验证Msg信息");
			
			Logger.comment("用该阿里账号再次登陆");
			UserCallService.regByAli(aliUserId, phone, true, "登录成功");;
			Logger.comment("验证用户绑定了阿里账号");
			thirdParty.clear();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.ALI, aliUserId, true);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_UnBindThirdPartyAccountDto_003() {
		Logger.start(false,"用户未绑定第三方账号，解绑失败");
		try {
			Map thirdParty = userWapper.selectOneThirdPartyBindPhone("iYmtUserId", "sUnionId", "Ymt_User_At_Wexin_Identify");
			Map user = UserCallService.registerUser(TestDataManager.getEmail(), TestDataManager.getPhoneNum(),null);
			unbindthirdpartyaccountdtoBean.setThirdPartyId(thirdParty.get("sUnionId").toString());
			unbindthirdpartyaccountdtoBean.setThirdPartyType(ThirdPartyType.WEIXIN);
			unbindthirdpartyaccountdtoBean.setUserId((Integer)user.get("userId"));
			unbindthirdpartyaccountdtoCall.setData(unbindthirdpartyaccountdtoBean);
			unbindthirdpartyaccountdtoCall.callService();			
			
			Logger.verifyEquals("此第三方账号不存在，无法解绑", unbindthirdpartyaccountdtoCall.getString("LastErrorMessage"), "验证Msg信息");
			Logger.verifyEquals("404", unbindthirdpartyaccountdtoCall.getString("ResponseCode"), "验证Code信息");
			Logger.verifyEquals("false", unbindthirdpartyaccountdtoCall.getString("Success"), "验证操作是否成功");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_UnBindThirdPartyAccountDto_004() {
		Logger.start(false,"第三方账号注册后,传入错误的第三方账号解绑,失败");
		try {
			//这里的逻辑改成了根据渠道会解绑这个渠道全部的账号，由于此账号是用唯一第三方绑定，所以解绑时候执行了解绑但是提示必须要有绑定账号的错误‘请设置登录账号及密码’
			Logger.comment("使用微博账号登陆");
			String weiboUserId = "BindWeibo_"+TestDataManager.getRandomNum(10);
			String phone = TestDataManager.getPhoneNum();
			Map user = UserCallService.regByWeibo(weiboUserId, phone, true, "注册成功");
			
			Map result = UserCallService.unbindThirdParty(((Double)user.get("userId")).intValue(), "notExistWeibo", ThirdPartyType.WEIBO);
			Logger.verifyEquals(false, result.get("Success"), "验证操作是否成功");
			Logger.verifyEquals(300d, result.get("ResponseCode"), "验证Code信息");
			Logger.verifyEquals("请设置登录账号及密码", result.get("LastErrorMessage"), "验证Msg信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_UnBindThirdPartyAccountDto_005() {
		Logger.start(true,"手机注册账号，绑定微博账号，解绑成功");
		try {
			Logger.comment("手机注册账号");
			String phone = TestDataManager.getPhoneNum();
			Map user = UserCallService.registerUser(null, phone,null);
			int userId = (Integer)user.get("userId");
			String loginId = user.get("loginId").toString();
			
			Logger.comment("绑定微博账号");
			String weiboUserId = "BindWeibo_"+TestDataManager.getRandomNum(10);
			UserCallService.regByWeibo(weiboUserId, phone, true, "登录成功");
			Logger.comment("验证用户绑定了微博账号");
			List<Map> thirdParty = new ArrayList<Map>();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIBO, weiboUserId, true);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
			
			Logger.comment("解绑微博账号");
			Map result = UserCallService.unbindThirdParty(userId, weiboUserId, ThirdPartyType.WEIBO);
			Logger.verifyEquals(200d, result.get("ResponseCode"), "验证Code");
			Logger.verifyEquals(true, result.get("Success"), "验证是否成功");
			Logger.verifyEquals("ok", result.get("Result"), "验证Msg信息");
			Logger.comment("验证用户解绑了微博账号");
			thirdParty.clear();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIBO, weiboUserId, false);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
			
			Logger.comment("用该微博账号再次登陆");
			UserCallService.regByWeibo(weiboUserId, phone, true, "登录成功");
			Logger.comment("验证用户绑定了微博账号");
			thirdParty.clear();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIBO, weiboUserId, true);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_UnBindThirdPartyAccountDto_006() {
		Logger.start(true,"邮箱注册账号，绑定微信账号，解绑成功");
		try {
			Logger.comment("邮箱注册账号");
			String phone = TestDataManager.getPhoneNum();
			Map user = UserCallService.registerUser(null, phone,null);
			int userId = (Integer)user.get("userId");
			String loginId = user.get("loginId").toString();
			
			Logger.comment("绑定微信账号");
			String unionId = "unbindweixin_"+TestDataManager.getRandomNum(10);
			UserCallService.checkThirdPartyNeedBindMobile(unionId, ThirdPartyType.WEIXIN, ECode.USER_YES);
			UserCallService.regByWeiXin(unionId, phone, true, "登录成功");
			Logger.comment("验证用户绑定了微信账号");
			List<Map> thirdParty = new ArrayList<Map>();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIXIN, unionId, true);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
			Logger.comment("解绑微信账号");
			Map result = UserCallService.unbindThirdParty(userId, unionId, ThirdPartyType.WEIXIN);
			Logger.verifyEquals(200d, result.get("ResponseCode"), "验证Code");
			Logger.verifyEquals(true, result.get("Success"), "验证是否成功");
			Logger.verifyEquals("ok", result.get("Result"), "验证Msg信息");
			Logger.comment("验证用户解绑了微信账号");
			thirdParty.clear();;
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIXIN, unionId, false);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
			
			Logger.comment("用该微信账号再次登陆");
			UserCallService.checkThirdPartyNeedBindMobile(unionId, ThirdPartyType.WEIXIN, ECode.USER_YES);
			UserCallService.regByWeiXin(unionId, phone, true, "登录成功");
			Logger.comment("验证用户绑定了微信账号");
			thirdParty.clear();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIXIN, unionId, true);
			Thread.sleep(1000);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_UnBindThirdPartyAccountDto_007() {
		Logger.start(true,"不输入第三方账号,用户绑定了微信账号，微博账号，阿里账号，依次解绑这些账号");
		try {
			Logger.comment("邮箱注册账号");
			String phone = TestDataManager.getPhoneNum();
			String email=TestDataManager.getEmail();
			Map user = UserCallService.registerUser(email, phone,null);
			int userId = (Integer)user.get("userId");
			String loginId = user.get("loginId").toString();
			
			Logger.comment("绑定微信账号");
			String unionId = "unbindweixin_"+TestDataManager.getRandomNum(10);
			UserCallService.checkThirdPartyNeedBindMobile(unionId, ThirdPartyType.WEIXIN, ECode.USER_YES);
			UserCallService.regByWeiXin(unionId, phone, true, "登录成功");
			Logger.comment("验证用户绑定了微信账号");
			List<Map> thirdParty = new ArrayList<Map>();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIXIN, unionId, true);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);

			Logger.comment("绑定微博账号");
			String weiboUserId = "BindWeibo_"+TestDataManager.getRandomNum(10);
			UserCallService.regByWeibo(weiboUserId, phone, true, "登录成功");
			Logger.comment("验证用户绑定了微博账号");
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIBO, weiboUserId, true);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
			
			Logger.comment("检查阿里账号是否需要绑定手机号");
			String aliUserId = "ali_"+TestDataManager.getRandomNum(7);
			UserCallService.checkThirdPartyNeedBindMobile(aliUserId, ThirdPartyType.ALI, ECode.USER_YES);
			Logger.comment("传入和微信同样的手机号，使用阿里账号登陆");
			UserCallService.regByAli(aliUserId, phone, true, "登录成功");
			
			Logger.comment("解绑微信账号");
			Map result = UserCallService.unbindThirdParty(userId, null, ThirdPartyType.WEIXIN);
			Logger.verifyEquals(200d, result.get("ResponseCode"), "验证Code");
			Logger.verifyEquals(true, result.get("Success"), "验证是否成功");
			Logger.verifyEquals("ok", result.get("Result"), "验证Msg信息");
					
			Logger.comment("解绑微博账号");
			result = UserCallService.unbindThirdParty(userId, null, ThirdPartyType.WEIBO);
			Logger.verifyEquals(200d, result.get("ResponseCode"), "验证Code");
			Logger.verifyEquals(true, result.get("Success"), "验证是否成功");
			Logger.verifyEquals("ok", result.get("Result"), "验证Msg信息");
			
			Logger.comment("解绑阿里账号");
			result = UserCallService.unbindThirdParty(userId, null, ThirdPartyType.ALI);
			Logger.verifyEquals(200d, result.get("ResponseCode"), "验证Code");
			Logger.verifyEquals(true, result.get("Success"), "验证是否成功");
			
			Logger.comment("调用接口验证用户绑定了微博，微信，阿里账号");
			thirdParty.clear();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.ALI, aliUserId, false);
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIXIN, unionId, false);
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIBO, weiboUserId, false);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_UnBindThirdPartyAccountDto_008() {
		Logger.start(true,"不输入第三方账号,用户绑定了微信账号，微博账号，阿里账号，依次解绑这些账号,解绑后再次绑定成功");
		try {
			Logger.comment("邮箱注册账号");
			String email=TestDataManager.getEmail();
			String phone = TestDataManager.getPhoneNum();
			Map user = UserCallService.registerUser(email, phone,null);
			int userId = (Integer)user.get("userId");
			String loginId = user.get("loginId").toString();
			
			Logger.comment("绑定微信账号");
			String unionId = "unbindweixin_"+TestDataManager.getRandomNum(10);
			UserCallService.checkThirdPartyNeedBindMobile(unionId, ThirdPartyType.WEIXIN, ECode.USER_YES);
			UserCallService.regByWeiXin(unionId, phone, true, "登录成功");
			Logger.comment("验证用户绑定了微信账号");
			List<Map> thirdParty = new ArrayList<Map>();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIXIN, unionId, true);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);

			Logger.comment("绑定微博账号");
			String weiboUserId = "BindWeibo_"+TestDataManager.getRandomNum(10);
			UserCallService.regByWeibo(weiboUserId, phone, true, "登录成功");
			Logger.comment("验证用户绑定了微博账号");
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIBO, weiboUserId, true);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
			
			Logger.comment("检查阿里账号是否需要绑定手机号");
			String aliUserId = "ali_"+TestDataManager.getRandomNum(7);
			UserCallService.checkThirdPartyNeedBindMobile(aliUserId, ThirdPartyType.ALI, ECode.USER_YES);
			Logger.comment("传入和微信同样的手机号，使用阿里账号登陆");
			UserCallService.regByAli(aliUserId, phone, true, "登录成功");
			
			Logger.comment("解绑微信账号");
			Map result = UserCallService.unbindThirdParty(userId, null, ThirdPartyType.WEIXIN);
			Logger.verifyEquals(200d, result.get("ResponseCode"), "验证Code");
			Logger.verifyEquals(true, result.get("Success"), "验证是否成功");
			Logger.verifyEquals("ok", result.get("Result"), "验证Msg信息");
					
			Logger.comment("解绑微博账号");
			result = UserCallService.unbindThirdParty(userId, null, ThirdPartyType.WEIBO);
			Logger.verifyEquals(200d, result.get("ResponseCode"), "验证Code");
			Logger.verifyEquals(true, result.get("Success"), "验证是否成功");
			Logger.verifyEquals("ok", result.get("Result"), "验证Msg信息");
			
			Logger.comment("解绑阿里账号");
			result = UserCallService.unbindThirdParty(userId, null, ThirdPartyType.ALI);
			Logger.verifyEquals(200d, result.get("ResponseCode"), "验证Code");
			Logger.verifyEquals(true, result.get("Success"), "验证是否成功");
			
			Logger.comment("调用接口验证用户绑定了微博，微信，阿里账号");
			thirdParty.clear();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.ALI, aliUserId, false);
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIXIN, unionId, false);
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIBO, weiboUserId, false);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
			
			Logger.comment("验证解绑后再次绑定账号");
			
			Logger.comment("绑定微信账号");
			unionId = "unbindweixin_"+TestDataManager.getRandomNum(10);
			UserCallService.checkThirdPartyNeedBindMobile(unionId, ThirdPartyType.WEIXIN, ECode.USER_YES);
			UserCallService.regByWeiXin(unionId, phone, true, "登录成功");
			Logger.comment("验证用户绑定了微信账号");
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIXIN, unionId, true);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);

			Logger.comment("绑定微博账号");
			weiboUserId = "BindWeibo_"+TestDataManager.getRandomNum(10);
			UserCallService.regByWeibo(weiboUserId, phone, true, "登录成功");
			Logger.comment("验证用户绑定了微博账号");
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIBO, weiboUserId, true);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
			
			Logger.comment("检查阿里账号是否需要绑定手机号");
			aliUserId = "ali_"+TestDataManager.getRandomNum(7);
			UserCallService.checkThirdPartyNeedBindMobile(aliUserId, ThirdPartyType.ALI, ECode.USER_YES);
			Logger.comment("传入和微信同样的手机号，使用阿里账号登陆");
			UserCallService.regByAli(aliUserId, phone, true, "登录成功");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_UnBindThirdPartyAccountDto_009() {
		Logger.start(true,"手机注册账号，绑定微信账号，解绑成功,再绑定成功,再解绑成功");
		try {
			Logger.comment("邮箱注册账号");
			String phone = TestDataManager.getPhoneNum();
			Map user = UserCallService.registerUser(null, phone,null);
			int userId = (Integer)user.get("userId");
			String loginId = user.get("loginId").toString();
			
			Logger.comment("绑定微信账号");
			String unionId = "unbindweixin_"+TestDataManager.getRandomNum(10);
			UserCallService.checkThirdPartyNeedBindMobile(unionId, ThirdPartyType.WEIXIN, ECode.USER_YES);
			UserCallService.regByWeiXin(unionId, phone, true, "登录成功");
			Logger.comment("验证用户绑定了微信账号");
			List<Map> thirdParty = new ArrayList<Map>();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIXIN, unionId, true);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
			
			Logger.comment("解绑微信账号");
			Map result = UserCallService.unbindThirdParty(userId, unionId, ThirdPartyType.WEIXIN);
			Logger.verifyEquals(200d, result.get("ResponseCode"), "验证Code");
			Logger.verifyEquals(true, result.get("Success"), "验证是否成功");
			Logger.verifyEquals("ok", result.get("Result"), "验证Msg信息");
			Logger.comment("验证用户解绑了微信账号");
			thirdParty.clear();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIXIN, unionId, false);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
			
			
			Logger.comment("再次绑定微信账号");
			String unionId2 = "unbindweixin_"+TestDataManager.getRandomNum(10);
			UserCallService.checkThirdPartyNeedBindMobile(unionId2, ThirdPartyType.WEIXIN, ECode.USER_YES);
			UserCallService.regByWeiXin(unionId2, phone, true, "登录成功");
			
			Logger.comment("再次解绑微信账号");
			//这里有老版本bug,传入第一次绑定id需要可以解绑第二个
			Map result2 = UserCallService.unbindThirdParty(userId, unionId, ThirdPartyType.WEIXIN);
			Logger.verifyEquals(200d, result2.get("ResponseCode"), "验证Code");
			Logger.verifyEquals(true, result2.get("Success"), "验证是否成功");
			Logger.verifyEquals("ok", result2.get("Result"), "验证Msg信息");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}